#include "MoveSniperIntoPositionState.h"
#include "SniperAssasinateTanksState.h"
#include "PDController.h"

MoveSniperIntoPositionState::MoveSniperIntoPositionState(void)
{
	target = new AttractiveField(Vector2(280, -180));
}


MoveSniperIntoPositionState::~MoveSniperIntoPositionState(void)
{
	delete target;
}

Command MoveSniperIntoPositionState::GetCommand(MultiAgent* agent) {
	Vector2 tank_pos(agent->getTank()->pos[0], agent->getTank()->pos[1]);
	Vector2 trajectory = target->get_trajectory(tank_pos);
	
	// If we are in position, take out the tanks
	if (trajectory.magnitude() < 50) {
		agent->setState(new SniperAssasinateTanksState());
		return agent->GetCommand();
	}

	return PDController::instance()->GetComand(agent->getTank(), trajectory);
}
